home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / sun / volume1 / tooltool2.1c / part06 < prev    next >
Encoding:
Internet Message Format  |  1989-06-06  |  32.7 KB

  1. Path: uunet!husc6!rutgers!aramis.rutgers.edu!dartagnan.rutgers.edu!mcgrew
  2. From: mcgrew@dartagnan.rutgers.edu (Charles Mcgrew)
  3. Newsgroups: comp.sources.sun
  4. Subject: v01i025:  Tooltool - a suntools user interface builder, Part 06/13
  5. Message-ID: <Jun.7.00.16.01.1989.23587@dartagnan.rutgers.edu>
  6. Date: 7 Jun 89 04:16:07 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 925
  9. Approved: mcgrew@aramis.rutgers.edu
  10.  
  11. Submitted-by: Chuck Musciano <chuck@trantor.harris-atd.com>
  12. Posting-number: Volume 1, Issue 25
  13. Archive-name: tooltool2.1c/part06
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 6 (of 13)."
  22. # Contents:  samples/keytool windows.c
  23. # Wrapped by chuck@melmac on Thu Jun  1 10:39:32 1989
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. if test -f 'samples/keytool' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'samples/keytool'\"
  27. else
  28. echo shar: Extracting \"'samples/keytool'\" \(15432 characters\)
  29. sed "s/^X//" >'samples/keytool' <<'END_OF_FILE'
  30. X#!/bin/sh
  31. X#  
  32. X#              ***keytool - Ken Laprade - 31 Oct 88 ***
  33. X#
  34. X#   A tooltool application to run a command with interactively redefineable
  35. X#   function keys.  C-S-M-right-mouse brings up a menu that controls key
  36. X#   definition.  Two keysets may be defined called primary and secondary.
  37. X#   Any undefined C-S-M-function-key will toggle between the two keysets.
  38. X#   Typical useful commands: /bin/ssh, /usr/ucb/telnet, /usr/ucb/rlogin.
  39. X#  
  40. X#
  41. Xif test "$1" = "-i" ; then
  42. X   shift;
  43. X   if test "$1" = "" ; then
  44. X      echo "Usage:  keytool [-i init_file] command [args ...]"; exit
  45. X   fi
  46. X   initfile=$1; shift;
  47. Xelse
  48. X   initfile="$HOME/.keytool"
  49. Xfi
  50. Xcmd=$1
  51. Xif /bin/test "$cmd" = "" ; then
  52. X   echo "Usage:  keytool [-i init_file] command [args ...]"; exit
  53. Xfi
  54. Xif test ! -x $cmd ; then
  55. X   echo "keytool: bad command: $cmd."; exit
  56. Xfi
  57. Xshift; 
  58. X
  59. Xtooltool $@ << END
  60. X
  61. Xapplication "$cmd"
  62. Xlabel "keytool"
  63. X
  64. X/* Fonts: */
  65. X#define POPUP_FONT "/usr/lib/fonts/fixedwidthfonts/screen.b.14"
  66. X#define TEXT_FONT "/usr/lib/fonts/fixedwidthfonts/screen.r.14"
  67. X#define SPECIAL_FONT "./keytool.r.14"
  68. X#define MENU_FONT "/usr/lib/fonts/fixedwidthfonts/screen.b.14"
  69. X
  70. X#define DEFAULT_INIT_FILE "./keytool.defaults"
  71. X
  72. X/* Macros for repetitive functions: */
  73. X#define init_keys() { \
  74. X    /* Initialize all keys, both primary and secondary keysets. */ \
  75. X    for (i = 0; i<cardinality(keyname); i++) keypress[0][keyname[i]] = empty_key; \
  76. X    keypress[1] = keypress[0]; \
  77. X  }
  78. X
  79. X#define read_init_file() { \
  80. X    /* Read key definitions from initialization file. */  \
  81. X    if (exists(init_file)) file = init_file; \
  82. X    else file = DEFAULT_INIT_FILE; \
  83. X    contents = output_of("/bin/cat ",file); \
  84. X    if (substr(contents,1,10) == "SEPARATOR=") { \
  85. X      item_separator = substr(contents,11,1); \
  86. X      line_separator = substr(contents,12,1); \
  87. X    } \
  88. X    else { \
  89. X      item_separator = "\t"; \
  90. X      line_separator = "\n"; \
  91. X    } \
  92. X    delimiters = line_separator; \
  93. X    lines = tokenize(contents); \
  94. X    delimiters = (item_separator,"'"); \
  95. X    keyset = 0; \
  96. X    abort = 0;    /* Flag from init_file_error popup window. */ \
  97. X    for (i=0; i<cardinality(lines) && !abort; i++) { \
  98. X      if (substr(lines[i],1,7) == "PRIMARY") keyset = 0; \
  99. X      else if (substr(lines[i],1,9) == "SECONDARY") keyset = 1; \
  100. X      else if (substr(lines[i],1,10) == "SEPARATOR=") ; \
  101. X      else { \
  102. X        s = index(lines[i],item_separator); \
  103. X        if (s > 0) { \
  104. X          k = substr(lines[i],1,s-1); \
  105. X          for (j=0,ok=0; j<cardinality(keyname) && !ok; j++) \
  106. X            if (keyname[j] == k) ok++; \
  107. X        } \
  108. X        if (!ok) {\
  109. X          error = lines[i]; \
  110. X          popup init_file_error; \
  111. X        } \
  112. X        else \
  113. X          keypress[keyset][k] = tokenize(substr(lines[i],s+1)); \
  114. X      } \
  115. X    } \
  116. X    delimiters = " \t\r\n"; \
  117. X    definition = keypress[active_keyset][keyname[selected_key]][selected_shift]; \
  118. X  }
  119. X
  120. Xinitialize {
  121. X  init_file = "$initfile";
  122. X  active_keyset = 0;
  123. X  selected_key = 0;
  124. X  selected_shift = 0;
  125. X  remove line_separator;
  126. X
  127. X  /* Initialize valid keynames and positions. */
  128. X  keynames = "L2 L3 L4 L9 L10 F1 F2 F3 F4 F5 F6 F7 F8 F9 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 LEFT MIDDLE RIGHT";
  129. X  keyname = tokenize(keynames);
  130. X  for (i=0; i<cardinality(keyname); i++) keynum[keyname[i]] = i;
  131. X  position = tokenize("NORMAL SHIFT CONTROL SHIFT_CONTROL META META_SHIFT META_CONTROL META_SHIFT_CONTROL");
  132. X  /* Define an empty key. */
  133. X  for (i=0; i<cardinality(position); i++) empty_key[i] = "";
  134. X
  135. X  /* Read key definitions from initialization file. */
  136. X  init_keys();
  137. X  read_init_file();
  138. X}
  139. X
  140. Xdialog init_file_error
  141. X  size 8 by 40 characters
  142. X  gadgets
  143. X    top
  144. X    font POPUP_FONT
  145. X    label at 10 10
  146. X      "Key definition error in keytool initialization file."
  147. X    end_label
  148. X    text error at 10 30
  149. X      display 40
  150. X      label "Error:"
  151. X      font SPECIAL_FONT
  152. X    end_text
  153. X    button at 90 50
  154. X      normal  "  Continue  " remove init_file_error;
  155. X    end_button
  156. X    button at 260 50
  157. X      normal  "   Abort   " { abort++; remove init_file_error; }
  158. X      control "   Quit" { abort++; exit; remove init_file_error; }
  159. X    end_button
  160. X  end_gadgets
  161. Xend_dialog
  162. X
  163. Xdialog write_file_error
  164. X  size 8 by 40 characters
  165. X  gadgets
  166. X    left
  167. X    align center
  168. X    font POPUP_FONT
  169. X    label
  170. X      "Cannot write to keytool initialization file!"
  171. X    end_label
  172. X    button
  173. X      normal  "  OK  " remove write_file_error;
  174. X    end_button
  175. X  end_gadgets
  176. Xend_dialog
  177. X
  178. Xdialog key_definition_window
  179. X  size 8 by 40 characters
  180. X  label "Key Definitions"
  181. X  gadgets
  182. X    top
  183. X    proportional
  184. X    font POPUP_FONT
  185. X#define XL1 10
  186. X#define XL2 48
  187. X#define XF1 91
  188. X#define XTEXT1 105
  189. X#define XF2 129
  190. X#define XF3 167
  191. X#define XTEXT2 177
  192. X#define XML 196
  193. X#define XTEXT3 205
  194. X#define XF4 250
  195. X#define XMM 315
  196. X#define XF5 333
  197. X#define XTEXT4 397
  198. X#define XF6 416
  199. X#define XMR 434
  200. X#define XF7 499
  201. X#define XTEXT5 522
  202. X#define XTEXT6 550
  203. X#define XTEXT7 575
  204. X#define XF8 582
  205. X#define XF9 620
  206. X#define XR1 663
  207. X#define XR2 701
  208. X#define XR3 739
  209. X#define Y1 5
  210. X#define Y2 30
  211. X#define Y3 55
  212. X#define Y4 80
  213. X#define Y5 105
  214. X#define YTEXT2 34
  215. X#define YTEXT3 59
  216. X#define YTEXT4 85
  217. X#define YTEXT5 109
  218. X
  219. X#define key_button(NAME,K,X,Y) button at X Y \
  220. X    normal NAME { selected_key = keynum["K"]; selected_shift = 0; \
  221. X                  definition = keypress[active_keyset]["K"][0]; } \
  222. X    shift NAME { selected_key = keynum["K"]; selected_shift = 1; \
  223. X                  definition = keypress[active_keyset]["K"][1]; } \
  224. X    control NAME { selected_key = keynum["K"]; selected_shift = 2; \
  225. X                  definition = keypress[active_keyset]["K"][2]; } \
  226. X    shift control NAME { selected_key = keynum["K"]; selected_shift = 3; \
  227. X                  definition = keypress[active_keyset]["K"][3]; } \
  228. X    meta NAME { selected_key = keynum["K"]; selected_shift = 4; \
  229. X                  definition = keypress[active_keyset]["K"][4]; } \
  230. X    meta shift NAME { selected_key = keynum["K"]; selected_shift = 5; \
  231. X                  definition = keypress[active_keyset]["K"][5]; } \
  232. X    meta control NAME { selected_key = keynum["K"]; selected_shift = 6; \
  233. X                  definition = keypress[active_keyset]["K"][6]; } \
  234. X    meta shift control NAME { selected_key = keynum["K"]; selected_shift = 7; \
  235. X                  definition = keypress[active_keyset]["K"][7]; } \
  236. X  end_button
  237. X
  238. X#define select_key(TEXT) TEXT definition = keypress[active_keyset][keyname[selected_key]][selected_shift];
  239. X
  240. X    key_button("L2 ",L2,XL2,Y1)
  241. X    key_button("L3 ",L3,XL1,Y2)
  242. X    key_button("L4 ",L4,XL2,Y2)
  243. X    key_button("L9 ",L9,XL1,Y5)
  244. X    key_button("L10",L10,XL2,Y5)
  245. X    key_button("L10",L10,XL2,Y5)
  246. X    key_button("F1 ",F1,XF1,Y1)
  247. X    key_button("F2 ",F2,XF2,Y1)
  248. X    key_button("   F3   ",F3,XF3,Y1)
  249. X    key_button("   F4   ",F4,XF4,Y1)
  250. X    key_button("   F5   ",F5,XF5,Y1)
  251. X    key_button("   F6   ",F6,XF6,Y1)
  252. X    key_button("   F7   ",F7,XF7,Y1)
  253. X    key_button("F8 ",F8,XF8,Y1)
  254. X    key_button("F9 ",F9,XF9,Y1)
  255. X    key_button("R1 ",R1,XR1,Y1)
  256. X    key_button("R2 ",R2,XR2,Y1)
  257. X    key_button("R3 ",R3,XR3,Y1)
  258. X    key_button("R4 ",R4,XR1,Y2)
  259. X    key_button("R5 ",R5,XR2,Y2)
  260. X    key_button("R6 ",R6,XR3,Y2)
  261. X    key_button("R7 ",R7,XR1,Y3)
  262. X    key_button("R8 ",R8,XR2,Y3)
  263. X    key_button("R9 ",R9,XR3,Y3)
  264. X    key_button("R10",R10,XR1,Y4)
  265. X    key_button("R11",R11,XR2,Y4)
  266. X    key_button("R12",R12,XR3,Y4)
  267. X    key_button("R13",R13,XR1,Y5)
  268. X    key_button("R14",R14,XR2,Y5)
  269. X    key_button("R15",R15,XR3,Y5)
  270. X    key_button(" MOUSE LEFT ",LEFT,XML,Y2)
  271. X    key_button("MOUSE MIDDLE",MIDDLE,XMM,Y2)
  272. X    key_button("MOUSE RIGHT ",RIGHT,XMR,Y2)
  273. X    button at XTEXT7 Y4
  274. X      normal " DONE " remove key_definition_window;
  275. X    end_button
  276. X    choice active_keyset at XTEXT3 YTEXT4
  277. X      display horizontal
  278. X      label "Keyset: "
  279. X      select_key("Primary  ")
  280. X      select_key("Secondary")
  281. X    end_choice
  282. X    choice selected_shift at XTEXT1 YTEXT5
  283. X      display current
  284. X      select_key(" NORMAL") select_key("  SHIFT") select_key("CONTROL") select_key("SH CTRL")
  285. X      select_key("   META") select_key(" M SHFT") select_key(" M CTRL") select_key("  M S C")
  286. X    end_choice
  287. X    choice selected_key at XTEXT2 YTEXT5
  288. X      display current
  289. X      select_key("L2") select_key("L3") select_key("L4") select_key("L9") select_key("L10")
  290. X      select_key("F1") select_key("F2") select_key("F3") select_key("F4") select_key("F5")
  291. X      select_key("F6") select_key("F7") select_key("F8") select_key("F9")
  292. X      select_key("R1") select_key("R2") select_key("R3") select_key("R4") select_key("R5")
  293. X      select_key("R6") select_key("R7") select_key("R8") select_key("R9") select_key("R10")
  294. X      select_key("R11") select_key("R12") select_key("R13") select_key("R14") select_key("R15")
  295. X      select_key("LFT") select_key("MID") select_key("RHT")
  296. X    end_choice
  297. X    text definition at XTEXT3 YTEXT5
  298. X      label ":"
  299. X      display 40
  300. X      font SPECIAL_FONT
  301. X      trigger ""
  302. X      ignore ""
  303. X    end_text
  304. X    button at XTEXT7 Y5
  305. X      normal "DEFINE" keypress[active_keyset][keyname[selected_key]][selected_shift] = definition;
  306. X    end_button
  307. X    button at XTEXT6 Y5
  308. X      normal "\t":SPECIAL_FONT definition = (definition,"\t");
  309. X      shift "\177":SPECIAL_FONT definition = (definition,"\177");
  310. X      control "^U":SPECIAL_FONT definition = (definition,"^U");
  311. X      shift control "^W":SPECIAL_FONT definition = (definition,"^W");
  312. X    end_button
  313. X    text init_file at XTEXT1 YTEXT3
  314. X      label "File:"
  315. X      display 29
  316. X      font TEXT_FONT
  317. X      completion " ^Z"
  318. X    end_text
  319. X    button at XTEXT7 Y3
  320. X      normal " SAVE " {
  321. X        if ((exists(init_file) && !writable(init_file)) || !writable(head(init_file)))
  322. X          popup write_file_error;
  323. X        else {
  324. X          /* Clear out lines array. */
  325. X          lines = 0;
  326. X          l = 0;
  327. X          if (item_separator == "") item_separator = "\t";
  328. X          if (line_separator == "") line_separator = "\n";
  329. X          lines[l++] = ("SEPARATOR=",item_separator);
  330. X          lines[l++] = "PRIMARY";
  331. X          delimiters = item_separator;
  332. X          for (i = 0; i<cardinality(keyname); i++) {
  333. X            for (j=0; j<cardinality(position); j++) {
  334. X              if (keypress[0][keyname[i]][j] == "")
  335. X                /* Put a '' in any unused slots as a placeholder for tokenize. */
  336. X                 temp[j] = "''";
  337. X              else temp[j] = keypress[0][keyname[i]][j];
  338. X            }
  339. X            lines[l++] = (keyname[i],item_separator,temp);
  340. X          }
  341. X          lines[l++] = "SECONDARY";
  342. X          for (i = 0; i<cardinality(keyname); i++) {
  343. X            for (j=0; j<cardinality(position); j++) {
  344. X              if (keypress[1][keyname[i]][j] == "")
  345. X                /* Put a '' in any unused slots as a placeholder for tokenize. */
  346. X                 temp[j] = "''";
  347. X              else temp[j] = keypress[1][keyname[i]][j];
  348. X            }
  349. X            lines[l++] = (keyname[i],item_separator,temp);
  350. X          } 
  351. X          delimiters = line_separator;
  352. X          system("/bin/cat > ",init_file," << 'END-OF-FILE'\n",lines,"\n");
  353. X          delimiters = " \t\r\n";
  354. X        }
  355. X      }
  356. X      shift " LOAD" {
  357. X        /* Read key definitions from initialization file. */
  358. X        init_keys();
  359. X        read_init_file();
  360. X      }
  361. X      control " Copy Primary -> Secondary" {
  362. X        keypress[1] = keypress[0];
  363. X        definition = keypress[active_keyset][keyname[selected_key]][selected_shift];
  364. X      }
  365. X      shift control " Copy Secondary -> Primary" {
  366. X        keypress[0] = keypress[1];
  367. X        definition = keypress[active_keyset][keyname[selected_key]][selected_shift];
  368. X      }
  369. X      meta "Default File" {
  370. X        if (exists("$initfile")) init_file = "$initfile";
  371. X        else init_file = DEFAULT_INIT_FILE;
  372. X      }
  373. X    end_button
  374. X    choice displayed_separator at XTEXT4 YTEXT3
  375. X      display current
  376. X      "Item Separator" { remove line_separator; display item_separator; }
  377. X      "Line Separator" { remove item_separator; display line_separator; }
  378. X    end_choice
  379. X    text item_separator at XTEXT5 YTEXT3
  380. X      label ":"
  381. X      display 1
  382. X      retain 1
  383. X      font SPECIAL_FONT
  384. X      trigger ""
  385. X      ignore ""
  386. X    end_text
  387. X    text line_separator at XTEXT5 YTEXT3
  388. X      label ":"
  389. X      display 1
  390. X      retain 1
  391. X      font SPECIAL_FONT
  392. X      trigger ""
  393. X      ignore ""
  394. X    end_text
  395. X    button at XTEXT6 Y3
  396. X#define set_separator(S) { if (displayed_separator) line_separator = S; \
  397. X              else item_separator = S; }
  398. X      normal "\t":SPECIAL_FONT set_separator("\t")
  399. X      shift "\177":SPECIAL_FONT set_separator("\177")
  400. X      control "^U":SPECIAL_FONT set_separator("^U")
  401. X      shift control "^W":SPECIAL_FONT set_separator("^W")
  402. X    end_button
  403. X  end_gadgets
  404. Xend_dialog
  405. X
  406. Xkeys
  407. X#define keydef(K)  key K \
  408. X    normal send keypress[active_keyset]["K"][0]; \
  409. X    shift send keypress[active_keyset]["K"][1]; \
  410. X    control send keypress[active_keyset]["K"][2]; \
  411. X    shift control send keypress[active_keyset]["K"][3]; \
  412. X    meta send keypress[active_keyset]["K"][4]; \
  413. X    meta shift send keypress[active_keyset]["K"][5]; \
  414. X    meta control send keypress[active_keyset]["K"][6]; \
  415. X    meta shift control { \
  416. X      if (keypress[active_keyset]["K"][7] == "") { \
  417. X        active_keyset = !active_keyset; \
  418. X        definition = keypress[active_keyset][keyname[selected_key]][selected_shift]; \
  419. X      } \
  420. X      else send keypress[active_keyset]["K"][7]; \
  421. X    } \
  422. X  end_key
  423. X
  424. X  keydef(L2)
  425. X  keydef(L3)
  426. X  keydef(L4)
  427. X  keydef(L9)
  428. X  keydef(L10)
  429. X  keydef(F1)
  430. X  keydef(F2)
  431. X  keydef(F3)
  432. X  keydef(F4)
  433. X  keydef(F5)
  434. X  keydef(F6)
  435. X  keydef(F7)
  436. X  keydef(F8)
  437. X  keydef(F9)
  438. X  keydef(R1)
  439. X  keydef(R2)
  440. X  keydef(R3)
  441. X  keydef(R4)
  442. X  keydef(R5)
  443. X  keydef(R6)
  444. X  keydef(R7)
  445. X  keydef(R8)
  446. X  keydef(R9)
  447. X  keydef(R10)
  448. X  keydef(R11)
  449. X  keydef(R12)
  450. X  keydef(R13)
  451. X  keydef(R14)
  452. X  keydef(R15)
  453. Xend_keys 
  454. X
  455. Xmouse
  456. X  base 0 characters
  457. X#define mousedef(K)  button K \
  458. X    /* Normal is left to perform the suntools functions. */ \
  459. X    shift send format(keypress[active_keyset]["K"][1],mouse_x,mouse_y); \
  460. X    control send format(keypress[active_keyset]["K"][2],mouse_x,mouse_y); \
  461. X    shift control send format(keypress[active_keyset]["K"][3],mouse_x,mouse_y); \
  462. X    meta send format(keypress[active_keyset]["K"][4],mouse_x,mouse_y); \
  463. X    meta shift send format(keypress[active_keyset]["K"][5],mouse_x,mouse_y); \
  464. X    meta control send format(keypress[active_keyset]["K"][6],mouse_x,mouse_y); \
  465. X    meta shift control send format(keypress[active_keyset]["K"][7],mouse_x,mouse_y); \
  466. X  end_button
  467. X
  468. X  mousedef(LEFT)
  469. X  mousedef(MIDDLE)
  470. X  button RIGHT
  471. X    /* Normal is left to perform the suntools functions. */
  472. X    shift send format(keypress[active_keyset]["RIGHT"][1],mouse_x,mouse_y);
  473. X    control send format(keypress[active_keyset]["RIGHT"][2],mouse_x,mouse_y);
  474. X    shift control send format(keypress[active_keyset]["RIGHT"][3],mouse_x,mouse_y);
  475. X    meta send format(keypress[active_keyset]["RIGHT"][4],mouse_x,mouse_y);
  476. X    meta shift send format(keypress[active_keyset]["RIGHT"][5],mouse_x,mouse_y);
  477. X    meta control send format(keypress[active_keyset]["RIGHT"][6],mouse_x,mouse_y);
  478. X    meta shift control menu
  479. X      "Define Keys":MENU_FONT
  480. X        display key_definition_window;
  481. X      "Use Primary":MENU_FONT
  482. X        { active_keyset = 0; definition = keypress[0][keyname[selected_key]][selected_shift]; }
  483. X      "Use Secondary":MENU_FONT
  484. X        { active_keyset = 1; definition = keypress[1][keyname[selected_key]][selected_shift]; }
  485. X      "Read Init File":MENU_FONT {
  486. X        /* Read key definitions from initialization file. */
  487. X        init_keys();
  488. X        read_init_file();
  489. X      }
  490. X    end_menu
  491. X  end_button
  492. Xend_mouse
  493. XEND
  494. END_OF_FILE
  495. if test 15432 -ne `wc -c <'samples/keytool'`; then
  496.     echo shar: \"'samples/keytool'\" unpacked with wrong size!
  497. fi
  498. chmod +x 'samples/keytool'
  499. # end of 'samples/keytool'
  500. fi
  501. if test -f 'windows.c' -a "${1}" != "-c" ; then 
  502.   echo shar: Will not clobber existing file \"'windows.c'\"
  503. else
  504. echo shar: Extracting \"'windows.c'\" \(14642 characters\)
  505. sed "s/^X//" >'windows.c' <<'END_OF_FILE'
  506. X/************************************************************************/
  507. X/*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  508. X/*                                    */
  509. X/*    Permission to use, copy, modify, and distribute this software    */
  510. X/*    and its documentation for any purpose and without fee is    */
  511. X/*    hereby granted, provided that the above copyright notice    */
  512. X/*    appear in all copies and that both that copyright notice and    */
  513. X/*    this permission notice appear in supporting documentation, and    */
  514. X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  515. X/*    used in advertising or publicity pertaining to distribution    */
  516. X/*    of the software without specific, written prior permission.    */
  517. X/*    Chuck Musciano and Harris Corporation make no representations    */
  518. X/*    about the suitability of this software for any purpose.  It is    */
  519. X/*    provided "as is" without express or implied warranty.        */
  520. X/*                                    */
  521. X/*    The sale of any product based wholely or in part upon the     */
  522. X/*    technology provided by tooltool is strictly forbidden without    */
  523. X/*    specific, prior written permission from Harris Corporation.    */
  524. X/*    Tooltool technology includes, but is not limited to, the source    */
  525. X/*    code, executable binary files, specification language, and    */
  526. X/*    sample specification files.                    */
  527. X/************************************************************************/
  528. X
  529. X
  530. X#include    <ctype.h>
  531. X
  532. X#include    "tooltool.h"
  533. X
  534. X#include    <suntool/tty.h>
  535. X
  536. X#define        TOOLTOOL_ICON        "tooltool.icon"
  537. X
  538. XPRIVATE    short    icon_bits[] = {
  539. X#include    TOOLTOOL_ICON
  540. X                  };
  541. Xmpr_static(tt_default_icon_pr, 64, 64, 1, icon_bits);
  542. X
  543. XEXPORT    Tty    tty = NULL;
  544. X
  545. XPUBLIC    event_proc(),
  546. X    notify_proc(),
  547. X    background_proc(),
  548. X    close_proc(),
  549. X    tty_handler(),
  550. X    tt_dialog_done();
  551. X
  552. X/************************************************************************/
  553. X/* This group of routines deals with laying out the tooltool windows    */
  554. X/************************************************************************/
  555. X
  556. X/************************************************************************/
  557. XPRIVATE    gadget_rows(d)
  558. X
  559. Xd_ptr    d;
  560. X
  561. X{    int    j, k, extra, count, row, height;
  562. X    g_ptr    b, next, start;
  563. X
  564. X    tt_build_images(d);
  565. X    for (next = d->gadgets, row = 4, count = 0; next; row += height + 4) {
  566. X       extra = (int) window_get(d->panel, WIN_WIDTH) - 4;
  567. X       for (b = start = next, height = 0; b; b = b->next)
  568. X          if (b->width + 4 > extra) { /* no room for this gadget */
  569. X             next = b;
  570. X             break;
  571. X             }
  572. X          else {
  573. X             extra -= b->width + 4;
  574. X             count++;
  575. X             if (b->height > height)
  576. X                height = b->height;
  577. X             }
  578. X       if (b == NULL)
  579. X          next = NULL;
  580. X       if (next == start) {
  581. X          next = start->next;
  582. X          height = start->height;
  583. X          count++;
  584. X          }
  585. X       if (!d->justified)
  586. X          extra = 0;
  587. X       for (b = start, j = 4, count--; b != next; b = b->next) {
  588. X          if (d->g_align == ALIGN_TOP)
  589. X             k = row;
  590. X          else if (d->g_align == ALIGN_MIDDLE)
  591. X             k = row + (height - b->height) / 2;
  592. X          else
  593. X             k = row + height - b->height;
  594. X          tt_make_gadget(d, b, j, k);
  595. X          if (count > 0) {
  596. X             j += b->width + 4 + (extra / count);
  597. X             extra -= extra / count--;
  598. X             }
  599. X          }
  600. X       }
  601. X    panel_fit_height(d->panel);
  602. X}
  603. X
  604. X/************************************************************************/
  605. XPRIVATE    gadget_columns(d)
  606. X
  607. Xd_ptr    d;
  608. X
  609. X{    int    j, k, extra, count, col, width;
  610. X    g_ptr    b, next, start;
  611. X
  612. X    tt_build_images(d);
  613. X    for (next = d->gadgets, col = count = 0; next; col += width + 4) {
  614. X       extra = (int) window_get(d->panel, WIN_HEIGHT) - 4;
  615. X       for (b = start = next, width = 0; b; b = b->next)
  616. X          if (b->height + 4 > extra) { /* no room for this gadget */
  617. X             next = b;
  618. X             break;
  619. X             }
  620. X          else {
  621. X             extra -= b->height + 4;
  622. X             count++;
  623. X             if (b->width > width)
  624. X                width = b->width;
  625. X             }
  626. X       if (b == NULL)
  627. X          next = NULL;
  628. X       if (next == start) {
  629. X          next = start->next;
  630. X          width = start->width;
  631. X          count++;
  632. X          }
  633. X       if (!d->justified)
  634. X          extra = 0;
  635. X       for (b = start, j = 4, count--; b != next; b = b->next) {
  636. X          if (d->g_align == ALIGN_TOP)
  637. X             k = 4 + col;
  638. X          else if (d->g_align == ALIGN_MIDDLE)
  639. X             k = 4 + col + (width - b->width) / 2;
  640. X          else
  641. X             k = 4 + col + width - b->width;
  642. X          tt_make_gadget(d, b, k, j);
  643. X          if (count > 0) {
  644. X             j += b->height + 4 + (extra / count);
  645. X             extra -= extra / count--;
  646. X             }
  647. X          }
  648. X       }
  649. X    panel_fit_width(d->panel);
  650. X}
  651. X
  652. X/************************************************************************/
  653. XEXPORT    build_window(argc, argv)
  654. X
  655. Xint    argc;
  656. Xchar    **argv;
  657. X
  658. X{    int    i, j, w, h;
  659. X    g_ptr    b, start, next;
  660. X    char    *args[64];
  661. X    struct    pixrect    *icon_pr;
  662. X    Icon    ic;
  663. X    Rect    *fr, *sr;
  664. X    d_ptr    d;
  665. X    static    char    *pos_hack[5];
  666. X
  667. X    if (tt_icon != NULL)
  668. X       icon_pr = tt_load_icon(tt_icon);
  669. X    else
  670. X       icon_pr = &tt_default_icon_pr;
  671. X    ic = icon_create(ICON_IMAGE, icon_pr,
  672. X             ICON_LABEL, "",
  673. X             ICON_WIDTH, icon_pr->pr_size.x,
  674. X             ICON_HEIGHT, icon_pr->pr_size.y,
  675. X             0);
  676. X    tt_base_window->frame = window_create(NULL, FRAME,
  677. X                 FRAME_ARGC_PTR_ARGV, &argc, argv,
  678. X                 FRAME_ICON, ic,
  679. X                 WIN_CLIENT_DATA, tt_base_window,
  680. X                  0);
  681. X    if (tt_base_window->label)
  682. X       window_set(tt_base_window->frame, FRAME_LABEL, tt_base_window->label, 0);
  683. X    if (tt_base_window->win_x != -1)
  684. X       window_set(tt_base_window->frame, WIN_X, tt_base_window->win_x, WIN_Y, tt_base_window->win_y, 0);
  685. X
  686. X    args[0] = tt_program;
  687. X    args[1] = POLLING_MAGIC_NUMBER;
  688. X    args[2] = safe_malloc(10);
  689. X    args[3] = safe_malloc(10);
  690. X    sprintf(args[2], "%d", tt_base_window->columns / (tt_base_window->is_chars? 1 : charwidth_of(tt_a_font)));
  691. X    sprintf(args[3], "%d", tt_base_window->rows / (tt_base_window->is_chars? 1 : charheight_of(tt_a_font)));
  692. X    tokenize(tt_application, &i, args + 4, 60);
  693. X    for (j = 1, i += 4; j < argc; j++)
  694. X       args[i++] = argv[j];
  695. X    args[i] = NULL;
  696. X    if (tt_base_window->gadgets == NULL) {
  697. X       if (*tt_application)
  698. X          tty = window_create(tt_base_window->frame, TTY,
  699. X                     tt_base_window->is_chars? WIN_ROWS : WIN_HEIGHT, tt_base_window->rows,
  700. X                     tt_base_window->is_chars? WIN_COLUMNS : WIN_WIDTH, tt_base_window->columns,
  701. X                     WIN_FONT, tt_a_font,
  702. X                     TTY_QUIT_ON_CHILD_DEATH, TRUE,
  703. X                     TTY_ARGV, args,
  704. X                      0);
  705. X       }
  706. X    else if (tt_base_window->gadget_pos == G_TOP) {
  707. X       tt_base_window->panel = window_create(tt_base_window->frame, PANEL,
  708. X                       WIN_ROWS, 24,
  709. X                       WIN_WIDTH, tt_base_window->is_chars? charwidth_of(tt_a_font) * tt_base_window->columns : tt_base_window->columns,
  710. X                       WIN_FONT, tt_base_window->g_font,
  711. X                    WIN_CLIENT_DATA, tt_base_window,
  712. X                       PANEL_ACCEPT_KEYSTROKE, !tt_base_window->text_items_exist,
  713. X                       PANEL_BACKGROUND_PROC, background_proc,
  714. X                       PANEL_NOTIFY_PROC, notify_proc,
  715. X                       PANEL_EVENT_PROC, event_proc,
  716. X                    0);
  717. X       gadget_rows(tt_base_window);
  718. X       if (*tt_application)
  719. X          tty = window_create(tt_base_window->frame, TTY,
  720. X                     tt_base_window->is_chars? WIN_ROWS : WIN_HEIGHT, tt_base_window->rows,
  721. X                     tt_base_window->is_chars? WIN_COLUMNS : WIN_WIDTH, tt_base_window->columns,
  722. X                     WIN_BELOW, tt_base_window->panel,
  723. X                     WIN_X, 0,
  724. X                     WIN_FONT, tt_a_font,
  725. X                     TTY_QUIT_ON_CHILD_DEATH, TRUE,
  726. X                     TTY_ARGV, args,
  727. X                      0);
  728. X       }
  729. X    else if (tt_base_window->gadget_pos == G_BOTTOM) {
  730. X       if (*tt_application)
  731. X          tty = window_create(tt_base_window->frame, TTY,
  732. X                     tt_base_window->is_chars? WIN_ROWS : WIN_HEIGHT, tt_base_window->rows,
  733. X                     tt_base_window->is_chars? WIN_COLUMNS : WIN_WIDTH, tt_base_window->columns,
  734. X                     WIN_FONT, tt_a_font,
  735. X                     TTY_QUIT_ON_CHILD_DEATH, TRUE,
  736. X                     TTY_ARGV, args,
  737. X                      0);
  738. X       if (tty && tt_base_window->rows > 0 && tt_base_window->columns > 0)
  739. X          tt_base_window->panel = window_create(tt_base_window->frame, PANEL,
  740. X                                         WIN_BELOW, tty,
  741. X                                         WIN_X, 0,
  742. X                                      0);
  743. X       else
  744. X          tt_base_window->panel = window_create(tt_base_window->frame, PANEL,
  745. X                                         WIN_X, 0,
  746. X                                         WIN_Y, 0,
  747. X                                      0);
  748. X       window_set(tt_base_window->panel,
  749. X                WIN_ROWS, 24,
  750. X                WIN_WIDTH, tt_base_window->is_chars? charwidth_of(tt_a_font) * tt_base_window->columns : tt_base_window->columns,
  751. X                WIN_FONT, tt_base_window->g_font,
  752. X             WIN_CLIENT_DATA, tt_base_window,
  753. X                PANEL_ACCEPT_KEYSTROKE, !tt_base_window->text_items_exist,
  754. X                PANEL_BACKGROUND_PROC, background_proc,
  755. X                PANEL_NOTIFY_PROC, notify_proc,
  756. X                PANEL_EVENT_PROC, event_proc,
  757. X                 0);
  758. X       gadget_rows(tt_base_window);
  759. X       }
  760. X    else if (tt_base_window->gadget_pos == G_LEFT)  {
  761. X       tt_base_window->panel = window_create(tt_base_window->frame, PANEL,
  762. X                       WIN_HEIGHT, tt_base_window->is_chars? charheight_of(tt_a_font) * tt_base_window->rows : tt_base_window->rows,
  763. X                       WIN_COLUMNS, 80,
  764. X                       WIN_FONT, tt_base_window->g_font,
  765. X                    WIN_CLIENT_DATA, tt_base_window,
  766. X                       PANEL_ACCEPT_KEYSTROKE, !tt_base_window->text_items_exist,
  767. X                       PANEL_BACKGROUND_PROC, background_proc,
  768. X                       PANEL_NOTIFY_PROC, notify_proc,
  769. X                       PANEL_EVENT_PROC, event_proc,
  770. X                    0);
  771. X       gadget_columns(tt_base_window);
  772. X       if (*tt_application)
  773. X          tty = window_create(tt_base_window->frame, TTY,
  774. X                     tt_base_window->is_chars? WIN_ROWS : WIN_HEIGHT, tt_base_window->rows,
  775. X                     tt_base_window->is_chars? WIN_COLUMNS : WIN_WIDTH, tt_base_window->columns,
  776. X                     WIN_RIGHT_OF, tt_base_window->panel,
  777. X                     WIN_Y, 0,
  778. X                     WIN_FONT, tt_a_font,
  779. X                     TTY_QUIT_ON_CHILD_DEATH, TRUE,
  780. X                     TTY_ARGV, args,
  781. X                      0);
  782. X       }
  783. X    else if (tt_base_window->gadget_pos == G_RIGHT) {
  784. X       if (*tt_application)
  785. X          tty = window_create(tt_base_window->frame, TTY,
  786. X                     tt_base_window->is_chars? WIN_ROWS : WIN_HEIGHT, tt_base_window->rows,
  787. X                     tt_base_window->is_chars? WIN_COLUMNS : WIN_WIDTH, tt_base_window->columns,
  788. X                     WIN_FONT, tt_a_font,
  789. X                     TTY_QUIT_ON_CHILD_DEATH, TRUE,
  790. X                     TTY_ARGV, args,
  791. X                      0);
  792. X       if (tty && tt_base_window->rows > 0 && tt_base_window->columns > 0)
  793. X          tt_base_window->panel = window_create(tt_base_window->frame, PANEL,
  794. X                                   WIN_RIGHT_OF, tty,
  795. X                                   WIN_Y, 0,
  796. X                                0);
  797. X       else
  798. X          tt_base_window->panel = window_create(tt_base_window->frame, PANEL,
  799. X                                   WIN_X, 0,
  800. X                                   WIN_Y, 0,
  801. X                                0);
  802. X       window_set(tt_base_window->panel,
  803. X                    WIN_HEIGHT, tt_base_window->is_chars? charheight_of(tt_a_font) * tt_base_window->rows : tt_base_window->rows,
  804. X                    WIN_COLUMNS, 80,
  805. X                    WIN_FONT, tt_base_window->g_font,
  806. X                 WIN_CLIENT_DATA, tt_base_window,
  807. X                    PANEL_ACCEPT_KEYSTROKE, !tt_base_window->text_items_exist,
  808. X                    PANEL_BACKGROUND_PROC, background_proc,
  809. X                    PANEL_NOTIFY_PROC, notify_proc,
  810. X                    PANEL_EVENT_PROC, event_proc,
  811. X                 0);
  812. X       gadget_columns(tt_base_window);
  813. X       }
  814. X    window_fit(tt_base_window->frame);
  815. X
  816. X    fr = (Rect *) window_get(tt_base_window->frame, FRAME_OPEN_RECT);
  817. X    sr = (Rect *) window_get(tt_base_window->frame, WIN_SCREEN_RECT);
  818. X    if (fr->r_left + fr->r_width > sr->r_width)
  819. X       window_set(tt_base_window->frame, WIN_X, max(sr->r_width - fr->r_width, 0), 0);
  820. X    if (fr->r_top + fr->r_height > sr->r_height)
  821. X       window_set(tt_base_window->frame, WIN_Y, max(sr->r_height - fr->r_height, 0), 0);
  822. X
  823. X    fr = (Rect *) window_get(tt_base_window->frame, FRAME_CLOSED_RECT);
  824. X    for (d = tt_base_window->next; d; d = d->next) {
  825. X       if (d->g_align == NO_ALIGN)
  826. X          d->g_align = ALIGN_TOP;
  827. X       pos_hack[0] = "";
  828. X       pos_hack[1] = "-WP";
  829. X       pos_hack[2] = safe_malloc(7);
  830. X       pos_hack[3] = safe_malloc(7);
  831. X       pos_hack[4] = NULL;
  832. X       sprintf(pos_hack[2], "%d", fr->r_left);
  833. X       sprintf(pos_hack[3], "%d", fr->r_top);
  834. X       d->frame = window_create(tt_base_window->frame, FRAME,
  835. X                          FRAME_SHOW_LABEL, FALSE,
  836. X                          FRAME_DONE_PROC, tt_dialog_done,
  837. X                          FRAME_ARGS, 4, pos_hack,
  838. X                          WIN_CLIENT_DATA, d,
  839. X                       0);
  840. X       if (d->label)
  841. X          window_set(d->frame, FRAME_LABEL, d->label, FRAME_SHOW_LABEL, TRUE, 0);
  842. X       d->panel = window_create(d->frame, PANEL,
  843. X                          WIN_HEIGHT, d->is_chars? charwidth_of(d->g_font) * d->rows : d->rows,
  844. X                          WIN_WIDTH, d->is_chars? charwidth_of(d->g_font) * d->columns : d->columns,
  845. X                          WIN_FONT, d->g_font,
  846. X                          WIN_CLIENT_DATA, d,
  847. X                          PANEL_ACCEPT_KEYSTROKE, !d->text_items_exist,
  848. X                          PANEL_BACKGROUND_PROC, background_proc,
  849. X                          PANEL_NOTIFY_PROC, notify_proc,
  850. X                          PANEL_EVENT_PROC, event_proc,
  851. X                       0);
  852. X       if (d->gadget_pos == G_TOP || d->gadget_pos == G_BOTTOM)
  853. X          gadget_rows(d);
  854. X       else
  855. X          gadget_columns(d);
  856. X       window_fit(d->panel);
  857. X       window_fit(d->frame);
  858. X       }
  859. X
  860. X    notify_interpose_event_func(tt_base_window->frame, close_proc, NOTIFY_SAFE);
  861. X    if (tt_base_window->panel)
  862. X       notify_interpose_event_func(tt_base_window->panel, close_proc, NOTIFY_SAFE);
  863. X
  864. X    if (tty) {
  865. X       notify_interpose_event_func(tty, tty_handler, NOTIFY_SAFE);
  866. X       tt_ttymenu = (Menu) window_get(tty, WIN_MENU);
  867. X       }
  868. X
  869. X    if (tty == NULL || tt_base_window->rows <= 0 || tt_base_window->columns <= 0) {
  870. X       if (tty)
  871. X          window_set(tty, WIN_SHOW, FALSE, 0);
  872. X       if (tt_base_window->panel)
  873. X          window_fit(tt_base_window->panel);
  874. X       window_fit(tt_base_window->frame);
  875. X       }
  876. X
  877. X    fr = (Rect *) window_get(tt_base_window->frame, FRAME_OPEN_RECT);
  878. X    window_set(tt_base_window->frame, WIN_X, 0, WIN_Y, 0, 0);
  879. X    for (d = tt_base_window->next; d; d = d->next)
  880. X       if (d->win_x != -1) {
  881. X          window_set(d->frame, WIN_X, d->win_x, WIN_Y, d->win_y, 0);
  882. X          w = (int) window_get(d->frame, WIN_WIDTH);
  883. X          h = (int) window_get(d->frame, WIN_HEIGHT);
  884. X          if (d->win_x + w > sr->r_width)
  885. X             window_set(d->frame, WIN_X, max(sr->r_width - w, 0), 0);
  886. X          if (d->win_y + h > sr->r_height)
  887. X             window_set(d->frame, WIN_Y, max(sr->r_height - h, 0), 0);
  888. X          }
  889. X       else
  890. X          window_set(d->frame,
  891. X                   WIN_X, (sr->r_width - (int) window_get(d->frame, WIN_WIDTH)) / 2,
  892. X                   WIN_Y, (sr->r_height - (int) window_get(d->frame, WIN_HEIGHT)) / 2,
  893. X                   0);
  894. X    window_set(tt_base_window->frame, WIN_X, fr->r_left, WIN_Y, fr->r_top, 0);
  895. X
  896. X    init_function_fix(tt_base_window->frame);
  897. X    if (tty)
  898. X       init_function_fix(tty);
  899. X    if (tt_base_window->panel)
  900. X       init_function_fix(tt_base_window->panel);
  901. X    for (d = tt_base_window->next; d; d = d->next) {
  902. X       init_function_fix(d->frame);
  903. X       init_function_fix(d->panel);
  904. X       }
  905. X
  906. X    tt_do_action(tt_initial_action);
  907. X}
  908. END_OF_FILE
  909. if test 14642 -ne `wc -c <'windows.c'`; then
  910.     echo shar: \"'windows.c'\" unpacked with wrong size!
  911. fi
  912. # end of 'windows.c'
  913. fi
  914. echo shar: End of archive 6 \(of 13\).
  915. cp /dev/null ark6isdone
  916. MISSING=""
  917. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 ; do
  918.     if test ! -f ark${I}isdone ; then
  919.     MISSING="${MISSING} ${I}"
  920.     fi
  921. done
  922. if test "${MISSING}" = "" ; then
  923.     echo You have unpacked all 13 archives.
  924.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  925. else
  926.     echo You still need to unpack the following archives:
  927.     echo "        " ${MISSING}
  928. fi
  929. ##  End of shell archive.
  930. exit 0
  931.  
  932. Chuck Musciano            ARPA  : chuck@trantor.harris-atd.com
  933. Harris Corporation         Usenet: ...!uunet!x102a!trantor!chuck
  934. PO Box 37, MS 3A/1912        AT&T  : (407) 727-6131
  935. Melbourne, FL 32902        FAX   : (407) 727-{5118,5227,4004}
  936.